package zabbix

import (
	"encoding/json"
	"errors"
)

func HostprototypeCreateData() (string,map[string]interface{}) {
	method := "hostprototype.create"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "host": "{#VM.NAME}",
        "ruleid": "23542",
        "groupLinks": [
            {
                "groupid": "2"
            }
        ],
        "groupPrototypes": [
            {
                "name": "{#HV.NAME}"
            }
        ]

	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func HostprototypeDeleteData() (string,map[string]interface{}) {
	method := "hostprototype.Delete"
	var data map[string]interface{}
	jsonstr := []byte(`[
		"10103",
		"10105"
	]`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func HostprototypeUpdateData() (string,map[string]interface{}) {
	method := "hostprototype.update"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "hostid": "10092",
        "status": 1
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func HostprototypeGetData() (string,map[string]interface{}) {
	method := "hostprototype.get"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "output": "extend",
        "selectGroupLinks": "extend",
        "selectGroupPrototypes": "extend",
        "discoveryids": "23554"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func HostprototypeCrate(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := HostprototypeCreateData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func HostprototypeDelete(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := HostprototypeDeleteData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func HostprototypeUpdate(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := HostprototypeUpdateData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func HostprototypeGet(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := HostprototypeGetData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}



